import axios, { type AxiosPromise } from "axios"
import { service } from "../loginApi"

export function getEmployment():AxiosPromise<RestResponse<any>> {
    return service({
        url: '/employment/getLists',
        method: 'get', // default
        // params: {
        //     eid: paramData.eid,
        //     ename:paramData.ename
        //   }
    });
}

export function getEmployById(eid:string):AxiosPromise<RestResponse<any>> {
    return service({
        url: '/employment/getEmpById',
        method: 'get', // default
        params: {
            id: eid
          }
    });
}

export function deleteEmpById(eid:number):AxiosPromise<RestResponse<any>> {
    return service({
        url: '/employment/deleteById',
        method: 'get', // default
        params: {
            id: eid
          }
    });
}

export function saveEmployment(data:employmentModel):AxiosPromise<RestResponse<any>> {
        var formData = new FormData();
        formData.append("ename", data.ename!!);
        formData.append("eage", data.eage!!.toString());
        formData.append("sex", data.sex!!);
        formData.append("idcard", data.idcard!!);
        formData.append("eaddr",data.eaddr!!);
        return service({
        url: '/employment/add',
        method: 'post',
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        data: formData
    });
}

export function updateEmp(data:employmentModel):AxiosPromise<RestResponse<any>> {
    var formData = new FormData();
        formData.append("eid",data.eid!!.toString());
        formData.append("ename", data.ename!!);
        formData.append("eage", data.eage!!.toString());
        formData.append("sex", data.sex!!);
        formData.append("idcard", data.idcard!!);
        formData.append("eaddr",data.eaddr!!);
        return service({
        url: '/employment/update',
        method: 'post',
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        data: formData
    });
}